package com.anyou.mall.rule.service.impl;

import java.util.List;
import com.anyou.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anyou.mall.rule.mapper.JfRuleMapper;
import com.anyou.mall.rule.domain.JfRule;
import com.anyou.mall.rule.service.IJfRuleService;

/**
 * 邀请好友规则Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-14
 */
@Service
public class JfRuleServiceImpl implements IJfRuleService
{
    @Autowired
    private JfRuleMapper jfRuleMapper;

    /**
     * 查询邀请好友规则
     *
     * @param jfRuleId 邀请好友规则主键
     * @return 邀请好友规则
     */
    @Override
    public JfRule selectJfRuleByJfRuleId(Long jfRuleId)
    {
        return jfRuleMapper.selectJfRuleByJfRuleId(jfRuleId);
    }

    /**
     * 查询邀请好友规则列表
     *
     * @param jfRule 邀请好友规则
     * @return 邀请好友规则
     */
    @Override
    public List<JfRule> selectJfRuleList(JfRule jfRule)
    {
        return jfRuleMapper.selectJfRuleList(jfRule);
    }

    /**
     * 新增邀请好友规则
     *
     * @param jfRule 邀请好友规则
     * @return 结果
     */
    @Override
    public int insertJfRule(JfRule jfRule)
    {
        jfRule.setCreateTime(DateUtils.getNowDate());
        //查看当前类型的是否存在
        JfRule jfRule1 = new JfRule();
        jfRule1.setRuleType(jfRule.getRuleType());
        List<JfRule> jfRules = jfRuleMapper.selectJfRuleList(jfRule1);
        if(jfRules.size()>0){
            throw new RuntimeException("当前类型已存在");
        }
        return jfRuleMapper.insertJfRule(jfRule);
    }

    /**
     * 修改邀请好友规则
     *
     * @param jfRule 邀请好友规则
     * @return 结果
     */
    @Override
    public int updateJfRule(JfRule jfRule)
    {
        jfRule.setUpdateTime(DateUtils.getNowDate());
        int i = jfRuleMapper.updateJfRule(jfRule);
//        int i = jfRuleMapper.updateById(jfRule);
        return i;
    }

    /**
     * 批量删除邀请好友规则
     *
     * @param jfRuleIds 需要删除的邀请好友规则主键
     * @return 结果
     */
    @Override
    public int deleteJfRuleByJfRuleIds(Long[] jfRuleIds)
    {
        return jfRuleMapper.deleteJfRuleByJfRuleIds(jfRuleIds);
    }

    /**
     * 删除邀请好友规则信息
     *
     * @param jfRuleId 邀请好友规则主键
     * @return 结果
     */
    @Override
    public int deleteJfRuleByJfRuleId(Long jfRuleId)
    {
        return jfRuleMapper.deleteJfRuleByJfRuleId(jfRuleId);
    }
}
